//
//  RandomNumber.m
//  Linear Birds
//
//  Created by How Charles on 11-12-3.
//  Copyright 2011 hust. All rights reserved.
//

#import "RandomNumber.h"


@implementation RandomNumber

#pragma mark ////分享我用的产生特定区间随机数（整型和浮点型）的静态类方法
//分享我用的产生特定区间随机数（整型和浮点型）的静态类方法：
//！随机数的最大值
//#define ARC4RANDOM_MAX      0x100000000

+(NSInteger)createRandomsizeValueInt:(NSInteger)fromInt toInt:(NSInteger)toInt
{
    if (toInt < fromInt)
    {
        return toInt;
    }
    if (toInt == fromInt)  
    {
        return fromInt;
    }
    NSInteger randVal = arc4random() % (toInt - fromInt + 1) + fromInt;
    return randVal;
}

+(double)createRandomsizeValueDouble:(double)fromFloat toFloat:(double)toFloat
{
    if (toFloat < fromFloat)
    {
        return toFloat;
    }
    if (toFloat == fromFloat)  
    {
        return fromFloat;
    }
    double randVal = ((double)(arc4random() % RAND_MAX)) * (toFloat - fromFloat) /RAND_MAX + fromFloat;
    return randVal;
}

+(float)createRandomsizeValueFloat:(float)fromFloat toFloat:(float)toFloat
{
    if (toFloat < fromFloat)
    {
        return toFloat;
    }
    if (toFloat == fromFloat)  
    {
        return fromFloat;
    }
    float randVal = ((float)(arc4random() % RAND_MAX)) * (toFloat - fromFloat)/RAND_MAX + fromFloat;
    return randVal;
}
///////////////////////////////

@end
